/*
 * Created by JFormDesigner on Wed Jan 04 11:39:26 CST 2023
 */

package otherSAMS.ui;

//import com.intellij.ide.ui.laf.*;

import otherSAMS.dao.StudentDao;
import otherSAMS.model.Student;
import otherSAMS.util.ListToArray;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;


/**
 * @author txx
 */
public class StudentScore extends JFrame {
    public StudentScore() {
        initComponents();
    }

    public static void main(String[] args) {
        StudentScore studentScore = new StudentScore();
        studentScore.setVisible(true);
    }

    private void selectMouseClicked(MouseEvent e) {
        // TODO add your code here
        String studentName = studentNameField.getText().trim();
        StudentDao studentDao = new StudentDao();
        List<Student> studentList = studentDao.selectByStudentName(studentName);
        String[][] data;
        if (studentList != null && studentList.size() > 0) {
            data = ListToArray.listToArrayWay(studentList);
        } else {
            JOptionPane.showMessageDialog(this, "无结果");
            data = new String[0][];
        }
        table1.setModel(new DefaultTableModel(
                data, tableColumeTitle
        ));
        scrollPane1.setViewportView(table1);
    }

    private void exit(ActionEvent e) {
        this.dispose();
        // TODO add your code here
    }

    private void retur(ActionEvent e) {
        this.dispose();
        UserLogin userLogin = new UserLogin();
        userLogin.initComponents();
        userLogin.setVisible(true);
        // TODO add your code here
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        menuBar2 = new JMenuBar();
        menu1 = new JMenu();
        retur = new JButton();
        exit = new JButton();
        panel1 = new JPanel();
        studentNameField = new JTextField();
        select = new JButton();
        label1 = new JLabel();
        scrollPane1 = new JScrollPane();
        table1 = new JTable();
        label2 = new JLabel();
        menuBar1 = new JMenuBar();

        //======== this ========
        setTitle("\u6b22\u8fce\u4f7f\u7528\u5b66\u751f\u6210\u7ee9\u7ba1\u7406\u7cfb\u7edf\uff01");
        Container contentPane = getContentPane();

        //======== menuBar2 ========
        {
            menuBar2.setBackground(new Color(0x99ffff));

            //======== menu1 ========
            {
                menu1.setText("\u7528\u6237\u83dc\u5355");
                menu1.setBackground(new Color(0x3399ff));

                //---- retur ----
                retur.setText("\u8fd4\u56de");
                retur.addActionListener(e -> {
			exit(e);
			retur(e);
		});
                menu1.add(retur);

                //---- exit ----
                exit.setText("\u9000\u51fa\u7cfb\u7edf");
                exit.addActionListener(e -> exit(e));
                menu1.add(exit);
            }
            menuBar2.add(menu1);
        }
        setJMenuBar(menuBar2);

        //======== panel1 ========
        {
            panel1.setBackground(new Color(0xccffff));

            //---- select ----
            select.setText("\u67e5\u8be2");
            select.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    selectMouseClicked(e);
                }
            });

            //---- label1 ----
            label1.setText("\u59d3\u540d");

            //======== scrollPane1 ========
            {

                //---- table1 ----
                table1.setModel(new DefaultTableModel(
                    new Object[][] {
                    },
                    new String[] {
                        "\u5e8f\u53f7", "\u59d3\u540d", "\u6027\u522b", "\u7535\u8bdd", "\u5b66\u53f7", "\u8bfe\u7a0b\u53f7", "\u7528\u6237\u53f7"
                    }
                ) {
                    boolean[] columnEditable = new boolean[] {
                        true, true, true, true, true, true, false
                    };
                    @Override
                    public boolean isCellEditable(int rowIndex, int columnIndex) {
                        return columnEditable[columnIndex];
                    }
                });
                table1.setBackground(Color.cyan);
                scrollPane1.setViewportView(table1);
            }

            //---- label2 ----
            label2.setText("\u4e2a\u4eba\u4fe1\u606f\u67e5\u8be2");
            label2.setFont(new Font("Microsoft YaHei UI", Font.PLAIN, 22));
            label2.setForeground(Color.blue);

            GroupLayout panel1Layout = new GroupLayout(panel1);
            panel1.setLayout(panel1Layout);
            panel1Layout.setHorizontalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                        .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(label1, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel1Layout.createParallelGroup()
                            .addComponent(label2)
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addComponent(studentNameField, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)
                                .addGap(55, 55, 55)
                                .addComponent(select)))
                        .addGap(101, 101, 101))
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 459, GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
            );
            panel1Layout.setVerticalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label1)
                            .addComponent(studentNameField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(select))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(label2)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 258, GroupLayout.PREFERRED_SIZE))
            );
        }

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addComponent(panel1, GroupLayout.PREFERRED_SIZE, 457, GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 1, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }


    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JMenuBar menuBar2;
    private JMenu menu1;
    private JButton retur;
    private JButton exit;
    private JPanel panel1;
    private JTextField studentNameField;
    private JButton select;
    private JLabel label1;
    private JScrollPane scrollPane1;
    private JTable table1;
    private JLabel label2;
    private JMenuBar menuBar1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
    private String[] tableColumeTitle = {"\u5e8f\u53f7", "\u59d3\u540d", "\u6027\u522b", "\u7535\u8bdd", "\u5b66\u53f7", "\u8bfe\u7a0b\u53f7", "\u7528\u6237\u53f7"};
}
